/********************************************************************

Write Date: 2015/08/17
Author: Apple
>>>> Implement class ResourceManager
	
*********************************************************************/
#pragma once
#include "ooputils_global.h"
#include <QString>
#include <QMap>
#include <QQueue>
#include "CommonExceptions.h"
#include "Singleton.h"
#include "Object.h"
#include "Ptr.h"



_NS_OOP_BEGIN



/**
 * 
 *
 * Thread-safe: false.
 *
 * @remarks 2015/08/17, Apple
 */
class ResourceManager : public Singleton< ResourceManager >
{

	friend class Singleton< ResourceManager >;
	friend class ResourceLoader;
	friend class ResourceSaver;
	friend class Object;

public:

	void setResourceDirectory (const QString& r_dir) throw (InvalidArgumentException);
	
	void releaseAll ();

private:

	QString _dir;
	QMap< QString, QPair < P_Object, size_t > > _objects;
	QQueue< QString > _loadSquence;

	ResourceManager ();

	~ResourceManager ();

	void _checkAndCorrectName (P_Object p_obj) const;

	bool _doesNameExist (const QString& r_name) const;

	void _recordLoadedObject (P_Object p_obj);

	void _clean ();

};



_NS_OOP_END